<template>
	<view class="content">
		<view class="hei20"></view>
		<view v-if="xhList.length == 0 && scList.length == 0" class="wid90 mar fowe800 foSi35">
			<view style="height: 50rpx;"></view>
			<view class="dis disJuC">
				<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
			</view>
			<view class="textCen mar-top20" style="color: #868686;">暂无收藏</view>
		</view>
		<view v-if="xhList.length > 0 || scList.length > 0" class="wid90 mar borRad20 bacFFF"
			style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
			<view v-if="xhList.length > 0">
				<view class="wid90 mar dis disAl fowe800 foSi40" style="height: 96rpx;">洗护</view>
				<view class="wid100" style="border-bottom: 1rpx dashed #E1DFDF;"></view>
				<block v-for="(item, index) in xhList" :key="index">
					<view v-if="item.goods" class="wid90 mar dis disAl" style="padding: 25rpx 0;" @click="tiaozhuan('/pages/toiletries/commodity?id='+item.goods.id)"
						@longpress="shanchu(index,0,item)">
						<view style="height: 115rpx;width: 23%;">
							<image :src="url+item.goods.pic.split(',')[0]" class="hei100" style="width: 115rpx;"></image>
						</view>
						<view style="width: 77%;">
							<view class="dis disAl disJuB">
								<view class="foSi25 fowe600">{{item.goods.name}}</view>
								<image src="../../static/shouchang1.png" style="width: 37rpx;height: 35rpx;"></image>
							</view>
							<view class="mar-top40 dis disAl disJuB">
								<view class="foSi25 fowe600" style="color: #37BCC3;">¥{{item.goods.price}}</view>
								<view class="foSi20" style="color: #A8AAAA;">收藏时间：{{item.createtime}}</view>
							</view>
						</view>
					</view>
					<view class="wid100" style="border-bottom: 1rpx dashed #E1DFDF;"></view>
				</block>
			</view>
			<view v-if="scList.length > 0">
				<view class="wid90 mar dis disAl fowe800 foSi40" style="height: 96rpx;">商城</view>
				<view v-if="scList.length != (index+1)" class="wid100" style="border-bottom: 1rpx dashed #E1DFDF;">
				</view>
				<block v-for="(item, index) in scList" :key="index">
					<view v-if="item.goods" class="wid90 mar dis disAl" style="padding: 25rpx 0;" @click="tiaozhuan('/pages/commodity/commodity?id='+item.goods.id)"
						@longpress="shanchu(index,1,item)">
						<view style="height: 115rpx;width: 23%;">
							<image :src="url+item.goods.pic.split(',')[0]" class="hei100" style="width: 115rpx;"></image>
						</view>
						<view style="width: 77%;">
							<view class="dis disAl disJuB">
								<view class="foSi25 fowe600">{{item.goods.name}}</view>
								<image src="../../static/shouchang1.png" style="width: 37rpx;height: 35rpx;"></image>
							</view>
							<view class="mar-top40 dis disAl disJuB">
								<view class="foSi25 fowe600" style="color: #37BCC3;">¥{{item.goods.price}}</view>
								<view class="foSi20" style="color: #A8AAAA;">收藏时间：{{item.createtime}}</view>
							</view>
						</view>
					</view>
					<view v-if="scList.length != (index+1)" class="wid100" style="border-bottom: 1rpx dashed #E1DFDF;">
					</view>
				</block>
			</view>
		</view>
		<view style="height: 50rpx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				xhList: [],
				scList: []
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			shanchu(index,i,item) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除这条数据吗?',
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: that.global.url + '/api/qianyu_petrol/gasstation_collect_del',
								method: "POST",
								header: {
									'site-id': that.global.site_id, //自定义请求头信息
									'token': uni.getStorageSync('token')
								},
								data: {
									id: item.id
								},
								success(res) {
									let result = res.data
									console.log(result)
									if (result.code == 1) {
										if(i == 0){
											that.xhList.splice(index, 1);
										}else{
											that.scList.splice(index, 1);
										}
									} else {
										uni.showToast({
											title: result.msg,
											icon: 'none',
											duration: 2000
										})
									}
								}
							})
						} else if (res.cancel) {
							//console.log('用户点击取消');
						}
					}
				});
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_collect',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						gas_station_id: uni.getStorageSync('jiaId')
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.xhList = result.data.xihu
							that.scList = result.data.shangcheng
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {}
</style>